﻿#include <iostream>
#ifndef _C_API
#include "cppDemo.h"
//#include "httpDemo.h"
#else
#include "cDemo.h"
#endif

#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "mswsock.lib")
 
#define CLINET_NUM 10

int main()
{
#ifndef _C_API
    IOCPService * pServ = new IOCPService;
    EventHandler eh;
#else
    TCPEventHandler eh;
    eh.onTcpClosed = onTcpClosed;
    eh.onTcpConnected = onTcpConnected;
    eh.onTcpReceive = onTcpReceive;
    eh.onTcpCanSend = onTcpCanSend;
    eh.onTcpAccept = onTcpAccept;
    IOCPService* pServ = (IOCPService*)ELP_Create();
#endif
    char privateData[] = "test private data";

    pServ->init();
    pServ->setEventHandler(&eh);

    ENDPOINT_ID id[CLINET_NUM];
    for (size_t i = 0; i < CLINET_NUM; i++)
    {
        id[i] = pServ->connect("127.0.0.1", 8985);
        pServ->setPrivate(id[i], privateData);
    }

    while (true)
    {
        std::string buffer;
        std::cin >> buffer;
        if (buffer == "exit")
            break;
        for (size_t i = 0; i < CLINET_NUM; i++)
        {
            pServ->sendMsg(id[i], buffer.c_str(), buffer.length());
        }
    }

#ifndef _C_API
    delete pServ;
#else
    ELP_Destory(pServ);
#endif

    return 0;
}